<html>
<head><meta charset="utf-8"><title>is_ method generation · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html">is_ method generation</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="225607345"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225607345" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225607345">(Feb 08 2021 at 20:59)</a>:</h4>
<p>Hello!</p>
<p>I am loving the new changelog with <code>is_</code> method generation. although there are a couple things which confuse me:</p>
<ul>
<li>Why does it use <code>matches!</code> even if the enum implements PartialEq?</li>
<li>Why can it not generate the methods for tuple/struct variants? this is a little frustrating when using it for things like ASTs.</li>
</ul>
<p>Id be wiling to PR both changes for learning more about RA.</p>



<a name="225610878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225610878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225610878">(Feb 08 2021 at 21:27)</a>:</h4>
<p>regarding point 2, this was already filed <a href="https://github.com/rust-analyzer/rust-analyzer/issues/7601">https://github.com/rust-analyzer/rust-analyzer/issues/7601</a> feel free to implement that <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="225611000"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225611000" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225611000">(Feb 08 2021 at 21:28)</a>:</h4>
<p>regarding point 1, what would be the benefit of using <code>PartialEq</code> over <code>matches!</code>?</p>



<a name="225618017"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225618017" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225618017">(Feb 08 2021 at 22:20)</a>:</h4>
<p>Matches is actually more efficient usually</p>



<a name="225618037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225618037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225618037">(Feb 08 2021 at 22:21)</a>:</h4>
<p>PartialEq is usually implemented in terms of a match</p>



<a name="225618665"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225618665" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225618665">(Feb 08 2021 at 22:27)</a>:</h4>
<p>Filed an additional bug regarding the lint: <a href="https://github.com/rust-analyzer/rust-analyzer/issues/7605">https://github.com/rust-analyzer/rust-analyzer/issues/7605</a></p>
<p>The generated methods should be appended, not prepended to the impl block</p>



<a name="225618769"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225618769" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225618769">(Feb 08 2021 at 22:28)</a>:</h4>
<p>Probably a matter of finding the last close <code>}</code> in the block, and then inserting the method right before that. This should probably be a new method in utils tho</p>



<a name="225634616"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225634616" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225634616">(Feb 09 2021 at 01:30)</a>:</h4>
<p>Where is the code for this assist located so i can take a look?</p>



<a name="225634700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225634700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225634700">(Feb 09 2021 at 01:31)</a>:</h4>
<p>lol nevermind i found it</p>



<a name="225656350"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225656350" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225656350">(Feb 09 2021 at 08:19)</a>:</h4>
<blockquote>
<p>Why does it use matches! even if the enum implements PartialEq?</p>
</blockquote>
<p>Also, <code>matches!</code> always works, while <code>eq</code> only works if it implements <code>PartialEq</code></p>



<a name="225680023"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225680023" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225680023">(Feb 09 2021 at 12:02)</a>:</h4>
<p>And filed another one <a href="https://github.com/rust-analyzer/rust-analyzer/issues/7607">https://github.com/rust-analyzer/rust-analyzer/issues/7607</a> -- already know how to fix this, will send through a patch later.</p>



<a name="225680082"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225680082" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Yoshua Wuyts <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225680082">(Feb 09 2021 at 12:03)</a>:</h4>
<p>(first time contributing  code to RA, still learning how the various parts of an assist fit together <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span> )</p>



<a name="225696725"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225696725" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225696725">(Feb 09 2021 at 14:26)</a>:</h4>
<p>Another issue i found is that it produces invalid intra doc links for its docs</p>



<a name="225696782"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225696782" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225696782">(Feb 09 2021 at 14:27)</a>:</h4>
<p>Since it just writes the variant without the enum beforehand</p>



<a name="225696848"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225696848" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225696848">(Feb 09 2021 at 14:27)</a>:</h4>
<p>This makes it fail check-doc-links CI which made me a bit confused when i pushed to my repo <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="225697002"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225697002" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Riccardo D&#x27;Ambrosio <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225697002">(Feb 09 2021 at 14:28)</a>:</h4>
<p>Maybe if it is trivial to see if the variants are in scope then use the variants directly and otherwise fully qualify them?</p>



<a name="225698933"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/is_%20method%20generation/near/225698933" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Laurențiu <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/is_.20method.20generation.html#225698933">(Feb 09 2021 at 14:41)</a>:</h4>
<p><span class="user-mention silent" data-user-id="276242">Riccardo D'Ambrosio</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/is_.20method.20generation/near/225697002">said</a>:</p>
<blockquote>
<p>Maybe if it is trivial to see if the variants are in scope then use the variants directly and otherwise fully qualify them?</p>
</blockquote>
<p>It seems reasonable to always qualify the variants with the enum name</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>